﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADC.DAL;

namespace ADC.BL
{
    public class RecruitmentFactory
    {
        /// <summary>
        /// Get all visible
        /// </summary>
        /// <returns></returns>
        public static List<Recruitment> GetAll()
        {
            var db = new dbADCEntities();
            return db.Recruitments.Where(d => d.IsVisibled != null && d.IsVisibled == true).OrderByDescending(d => d.ModifiedDate).ToList();
        }

        public static List<Recruitment> ListAll()
        {
            var db = new dbADCEntities();
            return db.Recruitments.OrderByDescending(d => d.ModifiedDate).ToList();
        }

        public static Recruitment GetByID(int RecruitmentID)
        {
            var db = new dbADCEntities();
            return db.Recruitments.Where(g => g.RecruitmentID == RecruitmentID).FirstOrDefault();
        }

        // Update Programe
        /// </summary>
        /// <param name="programe"></param>
        /// <returns></returns>
        public static int Update(Recruitment RecruitmentInfo)
        {
            try
            {
                var db = new dbADCEntities();
                var objRecruitment = new Recruitment();
                objRecruitment = db.Recruitments.Where(g => g.RecruitmentID == RecruitmentInfo.RecruitmentID).FirstOrDefault();
                objRecruitment.Title = RecruitmentInfo.Title;
                objRecruitment.BodyDetails = RecruitmentInfo.BodyDetails;
                objRecruitment.Body = RecruitmentInfo.Body;
                objRecruitment.ModifiedBy = RecruitmentInfo.ModifiedBy;
                objRecruitment.ModifiedDate = DateTime.Now;
                objRecruitment.IsVisibled = RecruitmentInfo.IsVisibled;
                if (!string.IsNullOrEmpty(RecruitmentInfo.ImagePath))
                {
                    objRecruitment.ImagePath = RecruitmentInfo.ImagePath;
                }

                return db.SaveChanges();
            }
            catch (Exception)
            {
                // Log here
                throw;
            }
        }

        public static int Delete(int RecruitmentID)
        {
            var db = new dbADCEntities();

            // Delete Programe
            var tourInfo = db.Recruitments.Where(g => g.RecruitmentID.Equals(RecruitmentID)).FirstOrDefault();
            db.DeleteObject(tourInfo);
            return db.SaveChanges();
        }

        public static Recruitment Insert(Recruitment RecruitmentInfo)
        {
            var db = new dbADCEntities();
            db.AddToRecruitments((RecruitmentInfo));
            db.SaveChanges();
            return RecruitmentInfo;
        }
    }
}
